/*
 * Create a class to play music.
 */
package ocbn.remotelab.GUI;

import java.io.InputStream;
import javax.microedition.media.MediaException;
import javax.microedition.media.Player;
import net.rim.device.api.ui.component.Dialog;

/**
 * Do Not mark for Phase III.
 * This class is not used.
 * @author c9zhuron
 */
public class playMusic {

    /** Java media player. */
    private Player player;

    /** The music file/ */
    String music = "HoundDog.mp3";

    /** Input the music. */
    InputStream input;

    /**
     * Create a constructor for play music.
     */
    public playMusic() {
        /** Input the music. */
        input = getClass().getResourceAsStream("/" + music);
    }

     /**
      * Create a constructor with a parameter of file to input.
      * @param music the music file to play.
      */
    public playMusic(String music) {
        this.music = music;
        input = getClass().getResourceAsStream("/" + music);
    }
    /**
     * Play the music.
     */
    public void play() {
        try {
            // The type of music to play.
            player = javax.microedition.media.Manager.
                    createPlayer(input, "audio/mp3");

            //Start the music.
            player.start();
        } catch (Exception e) {
            Dialog.alert("Error playing music");
        }
    }

    /**
     * Stop the music.
     * @throws MediaException
     */
    public void stop() throws MediaException{
        player.stop();
    }
}
